import {Injectable} from '../../nest/core'
import axios from 'axios'
import * as process from "process";

@Injectable()
export class TokenService {
  async getToken() {
    const {BAIDU_TOKEN_URL, CLIENT_ID, CLIENT_SECRET} = process.env

    const res = await axios.post(
      `${BAIDU_TOKEN_URL}?client_id=${CLIENT_ID}&client_secret=${CLIENT_SECRET}&grant_type=client_credentials`,
      {
        headers: {
          'Content-Type': 'application/json',
          'Accept': 'application/json'
        }
      })


    return res.data
  }
}